﻿set(wxWidgets_version
    3.3.1
    CACHE STRING "wxWidgets version")
set(file_name "wxWidgets-${wxWidgets_version}")
set(base_url "https://github.com/wxWidgets/wxWidgets/releases/download")
set(file_url "${base_url}/v${wxWidgets_version}/wxWidgets-${wxWidgets_version}.zip")
# https://github.com/wxWidgets/wxWidgets/releases/download/v3.3.1/wxWidgets-3.3.1.zip

wxt_download_zip_file(${file_url} ${file_name})
if(NOT EXISTS ${WXT_3RD_DIR}/${file_name})
  make_directory(${WXT_3RD_DIR}/${file_name})
  execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${WXT_3RD_DIR}/${file_name}.zip
                  WORKING_DIRECTORY ${WXT_3RD_DIR}/${file_name})
endif()

if(LINUX AND NOT APPLE)
  set(wxUSE_LIBICONV
      OFF
      CACHE BOOL "Use libiconv for wxWidgets")
endif()

set(WXT_WX_LOCAL_DIR "${WXT_3RD_DIR}/${file_name}/locale")
set(wxWidgets_ROOT_DIR ${WXT_LIBS_DIR}/${WXT_BUILD_FLAG}/${file_name})
if(EXISTS ${wxWidgets_ROOT_DIR})
  set(CMAKE_PREFIX_PATH ${wxWidgets_ROOT_DIR} ${CMAKE_PREFIX_PATH})
  find_package(wxWidgets CONFIG REQUIRED)
  if(NOT wxWidgets_FOUND)
    message(FATAL_ERROR "[wxTools-wxWidgets] wxWidgets not found")
  endif()
else()
  include_directories(${WXT_3RD_DIR}/${file_name}/include)
  add_subdirectory(${WXT_3RD_DIR}/${file_name})
  set(wxWidgets_LIBRARIES wx::base wx::aui wx::stc)
  wxt_install_package(${file_name})
endif()
